package com.neusoft.controller;

import com.neusoft.po.CommonResult;
import com.neusoft.po.DeliveryMan;
import com.neusoft.po.Orders;
import com.neusoft.service.DeliveryManService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/DeliveryMan")
@RefreshScope // 开启动态刷新
public class DeliveryManController {
	@Autowired
	private DeliveryManService deliveryManService;

	@GetMapping("/OrderList")
	public CommonResult<List> listOrdersById(DeliveryMan deliveryMan) throws Exception {
		return new CommonResult<List>(200, "success",
				deliveryManService.listOrdersById(deliveryMan.getDeliveryManId()));
	}

	@GetMapping("/UndeliveryOrders")
	public CommonResult<List> listUndeliveryOrders() throws Exception {
		return new CommonResult<List>(200, "success", deliveryManService.listUndeliveryOrders());
	}

	@PutMapping("/deliveryOrder/{orderId}/{deliveryManId}")
	public CommonResult<Integer> deliveryOrder(@PathVariable("orderId") Integer orderId,
			@PathVariable("deliveryManId") String deliveryManId) throws Exception {
		Orders order = new Orders();
		DeliveryMan deliveryMan = new DeliveryMan();
		order.setOrderId(orderId);
		deliveryMan.setDeliveryManId(deliveryManId);
		return new CommonResult<Integer>(200, "success",
				deliveryManService.deliveryOrder(order.getOrderId(), deliveryMan.getDeliveryManId()));
	}

	@GetMapping("/Login")
	public CommonResult<DeliveryMan> getDeliveryManByIdByPass(DeliveryMan deliveryMan) throws Exception {
		return new CommonResult<DeliveryMan>(200, "success", deliveryManService.getDeliveryManByIdByPass(deliveryMan));
	}

	@PostMapping("/DeliveryManId")
	public CommonResult<Integer> saveDeliveryMan(DeliveryMan deliveryMan) throws Exception {
		return new CommonResult<Integer>(200, "success", deliveryManService.saveDeliveryMan(deliveryMan));
	}

	@GetMapping("/DeliveryManId")
	public CommonResult<DeliveryMan> getDeliveryManById(DeliveryMan deliveryMan) throws Exception {
		return new CommonResult<DeliveryMan>(200, "success",
				deliveryManService.getDeliveryManById(deliveryMan.getDeliveryManId()));
	}

}